<?php

//Tabla de usuarios
class Application_Model_DbTable_User extends Zend_Db_Table_Abstract
{

    protected $_name = 'usuario';

	function authenticate($username, $password){
        try{

            Zend_Loader::loadClass('Zend_Auth_Adapter_DbTable');
            $dbAdapter = Zend_Db_Table::getDefaultAdapter();
            //$dbAdapter = Zend_Registry::get('dbAdapter');
            $authAdapter = new Zend_Auth_Adapter_DbTable($dbAdapter);
            $authAdapter->setTableName('usuario');
            $authAdapter->setIdentityColumn('username');
            $authAdapter->setCredentialColumn('password');
            
            // Set the input credential values to authenticate against
            $authAdapter->setIdentity($username);
            $authAdapter->setCredential($password);
            // do the authentication
            $auth = Zend_Auth::getInstance();
            $result = $auth->authenticate($authAdapter);
            if ($result->isValid()) {               
                 $data = $authAdapter->getResultRowObject(null,
                'password');
                $auth->getStorage()->write($data);
                return true;
            } else {
                return false;
            }
            
        }
        catch(Zend_Exception $e){
            throw $e;
        }
    }

}

